﻿using System;
using System.Reflection;
using ESoft.AspNetCore.Authentication;
using ESoft.AspNetCore.Login;
using Microsoft.Extensions.DependencyInjection;

namespace ESoft.AspNetCore
{
    /// <summary>
    /// ServiceCollection扩展
    /// </summary>
    public static class ServiceCollectionExtensions
    {
        /// <summary>
        /// 添加Header校验方式
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configureOptions"></param>
        public static void AddHeaderAuthentication(this IServiceCollection services, Action<HeaderAuthenticationOptions> configureOptions)
        {
            services.AddAuthentication(HeaderAuthenticationDefaults.AuthenticationSchema)
               .AddHeader(HeaderAuthenticationDefaults.AuthenticationSchema,
                  configureOptions);
            services.AddSingleton<ISessionService<IApplicationSession>, SessionService<IApplicationSession>>();
        }

        /// <summary>
        /// 添加Header校验方式
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configureOptions"></param>
        public static void AddCookieAuthentication(this IServiceCollection services, Action<HeaderAuthenticationOptions> configureOptions)
        {
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationSchema)
               .AddHeader(CookieAuthenticationDefaults.AuthenticationSchema, configureOptions);
            services.AddSingleton<ISessionService<IApplicationSession>, SessionService<IApplicationSession>>();
        }
    }
}
